var mapId = 910040001;

function init() {}

function setup(b, a) {
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    var b = em.newInstance("Vergamot" + a);
    b.setProperty("vergamotSummoned", "0");
    var d = b.setInstanceMap(mapId);
    d.resetFully();
    d.killAllMonsters(true);
    var c = em.getMonster(9601047);
    c.setOverrideStats();
    c.getChangedStats().hp = 9999999999;
    c.getChangedStats().exp = 100100000;
    c.heal();
    d.spawnMonsterOnGroundBelow(c, new java.awt.Point(51, 120));
    var c = em.getMonster(9601047);
    c.setOverrideStats();
    c.getChangedStats().hp = 999999999;
    c.getChangedStats().exp = 100000000;
    c.heal();
    d.spawnMonsterOnGroundBelow(c, new java.awt.Point(-409, 120));
    b.schedule("timeout", 300 * 1000);
    b.schedule("beginQuest", 1000);
    return b
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0))
}

function onPlayerRevived(b, a) {
    return false
}

function onTimeOut(a) {
    end(a)
}

function timeout(a) {
    end(a)
}

function onMapChanged(c, b, a) {
    if (a != 910040001) {
        c.unregisterPlayer(b);
        if (c.disposeIfPlayerBelow(0, 0)) {
            em.setProperty("state", "0");
            em.setProperty("leader", "true")
        }
    }
}

function onPlayerDisconnected(b, a) {
    return 0
}

function onMonsterKilled(a, b) {
    return 1
}

function playerExit(b, a) {
    b.unregisterPlayer(a);
    if (b.disposeIfPlayerBelow(0, 0)) {
        em.setProperty("state", "0");
        em.setProperty("leader", "true")
    }
}

function end(a) {
    var b = a.getMapInstance(910040001);
    a.broadcastPlayerMsg(1, "副本时间到了,你退出了副本~");
    a.disposeIfPlayerBelow(100, 450004000);
    em.setProperty("state", "0");
    em.setProperty("leader", "true")
}

function monsterSpawn(b) {
    var d = b.getMapInstance(910040001);
    if (d.getNumMonsters() <= 80) {
        for (var a = 0; a < 2; a++) {
            var c = em.getMonster(9601047);
            c.setOverrideStats();
            c.getChangedStats().hp = 28888;
            c.getChangedStats().exp = 30000000;
            c.heal();
            d.spawnMonsterOnGroundBelow(c, new java.awt.Point(51, 120))
        }
        for (var a = 0; a < 2; a++) {
            var c = em.getMonster(9601042);
            c.setOverrideStats();
            c.getChangedStats().hp = 25555;
            c.getChangedStats().exp = 3000000;
            c.heal();
            d.spawnMonsterOnGroundBelow(c, new java.awt.Point(-409, 120))
        }
        for (var a = 0; a < 2; a++) {
            var c = em.getMonster(9601043);
            c.setOverrideStats();
            c.getChangedStats().hp = 28555;
            c.getChangedStats().exp = 3000000;
            c.heal();
            d.spawnMonsterOnGroundBelow(c, new java.awt.Point(51, 120))
        }
        for (var a = 0; a < 4; a++) {
            var c = em.getMonster(9601044);
            c.setOverrideStats();
            c.getChangedStats().hp = 28555;
            c.getChangedStats().exp = 3000000;
            c.heal();
            d.spawnMonsterOnGroundBelow(c, new java.awt.Point(-409, 120))
        }
        b.schedule("monsterSpawn", 10000);
        d.broadcastMessage(em.getClock(10));
        em.getMapFactory().getMap(910040001).startSimpleMapEffect("羊羊大军在10秒后到达,请火速消灭,当前来袭大军数量" + d.getNumMonsters() + "", 5120037)
    } else {
        if (d.getNumMonsters() > 80 && d.getNumMonsters() < 100) {
            for (var a = 0; a < 2; a++) {
                var c = em.getMonster(9601045);
                c.setOverrideStats();
                c.getChangedStats().hp = 1055555;
                c.getChangedStats().exp = 3000000;
                c.heal();
                d.spawnMonsterOnGroundBelow(c, new java.awt.Point(51, 120))
            }
            for (var a = 0; a < 2; a++) {
                var c = em.getMonster(9601046);
                c.setOverrideStats();
                c.getChangedStats().hp = 1055555;
                c.getChangedStats().exp = 3000000;
                c.heal();
                d.spawnMonsterOnGroundBelow(c, new java.awt.Point(-409, 120))
            }
            for (var a = 0; a < 2; a++) {
                var c = em.getMonster(9601046);
                c.setOverrideStats();
                c.getChangedStats().hp = 1055555;
                c.getChangedStats().exp = 3000000;
                c.heal();
                d.spawnMonsterOnGroundBelow(c, new java.awt.Point(51, 120))
            }
            for (var a = 0; a < 4; a++) {
                var c = em.getMonster(9601045);
                c.setOverrideStats();
                c.getChangedStats().hp = 1055555;
                c.getChangedStats().exp = 3000000;
                c.heal();
                d.spawnMonsterOnGroundBelow(c, new java.awt.Point(-409, 120))
            }
            b.schedule("monsterSpawn", 10000);
            d.broadcastMessage(em.getClock(10));
            em.getMapFactory().getMap(910040001).startSimpleMapEffect("当前地图处于告急状态,请加强火力防止怪物增加,当前来袭大军数量" + d.getNumMonsters() + "！超过100只怪物将会退出副本", 5120037)
        } else {
            b.broadcastPlayerMsg(1, "你已被包围,失败退出了副本~");
            b.disposeIfPlayerBelow(100, 450004000);
            em.setProperty("state", "0");
            em.setProperty("leader", "true")
        }
    }
}

function beginQuest(a) {
    var b = a.getMapInstance(910040001);
    em.getMapFactory().getMap(910040001).startSimpleMapEffect("此副本总时间为5分钟,怪物大军在10秒后到达！请火速消灭", 5120037);
    a.schedule("monsterSpawn", 10000);
    b.broadcastMessage(em.getClock(10))
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {};